def maraphon(a):
    if a == 1: return False
    test = True
    k = a - 1
    while k > 1:
        if not a % k:
            test = False
            break
        k -= 1
        return test  
     
n = input() 
g = [] 
for i in range(len(n) + 1):
    for k in range(i,len(n) + 1):
        if i == k:
            continue
        a = int(n[i:k])
        if  maraphon(a):
            g += [a] 
print(max(g) if g else 0)
